<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8"/>
<title>キネクトなしでwebsocketを発信するデモ</title>
</head>
<body>
<h1 id="h1">test</h1>
<script type="text/javascript">
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////



/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

function initCS() {
  var wsUrl = "ws://localhost:8182";
  var webSocket = null;
  var state = 'wait';
  
  if(typeof WebSocket != "undefined") {
    webSocket = new WebSocket(wsUrl);
  }
  else if(typeof MozWebSocket != "undefined") {
    webSocket = new MozWebSocket(wsUrl);
  }

  if(webSocket) {
    console.log("init");
    webSocket.onopen = function() {
      console.log("opend");
    };

    webSocket.onmessage = function(msg) {
      console.log('onmessage', msg);
    };

    webSocket.onclose = function() {
      console.log("closed...");
    };

    //画面をクリックするとdetectとwaitを交互に発信
    window.onmousedown = function () {
      if (state === 'ditect') {
        console.log('send wait');
        webSocket.send('wait');
        state = 'wait';
      } else if (state === 'wait') {
        console.log('send ditect');
        webSocket.send('detect');
        state = 'ditect';
      }
    };
  }
  console.log(webSocket);
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

initCS();

</script>
</body>
</html>